package com.ruoyi.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.utils.file.FileUploadUtils;
import com.ruoyi.common.utils.file.FileUtils;
import com.ruoyi.domain.THonorAttchment;
import com.ruoyi.framework.config.ServerConfig;
import com.ruoyi.utils.AliOSSUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.domain.TCertificateDocument;
import com.ruoyi.service.ITCertificateDocumentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 证件信息Controller
 *
 * @author ruoyi
 * @date 2024-11-04
 */
@Slf4j
@RestController
@RequestMapping("/talent/document")
public class TCertificateDocumentController extends BaseController {
    @Autowired
    private ITCertificateDocumentService tCertificateDocumentService;



    /**
     * 根据人才id获取证件信息详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:document:query')")
    @GetMapping(value = "/list/{id}")
    public TableDataInfo getInfo(@PathVariable("id") Long id) {
        return getDataTable(tCertificateDocumentService.selectTCertificateDocumentById(id));
    }

    /**
     * 根据证件id获取证件信息详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:document:query')")
    @GetMapping(value = "/{certificateId}")
    public AjaxResult getInfoByTalentIdAndCertificateId(@PathVariable("certificateId") Long certificateId) {
        return success(tCertificateDocumentService.selectByIdCertificateId(certificateId));
    }
    /**
     * 获取附件信息
     */

    @PreAuthorize("@ss.hasPermi('system:info:query')")
    @GetMapping(value = "/attachment/{documentId}")
    public TableDataInfo getAttachment(@PathVariable Long documentId) {
        List<TCertificateDocument> list = tCertificateDocumentService.selectAttachmentById(documentId);
        return getDataTable(list);
    }


    /**
     * 新增证件信息
     */
//    @PreAuthorize("@ss.hasPermi('system:document:add')")
//    @Log(title = "证件信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody TCertificateDocument tCertificateDocument) {
        return toAjax(tCertificateDocumentService.insertTCertificateDocument(tCertificateDocument));
    }


    /**
     * 修改证件信息
     */
//    @PreAuthorize("@ss.hasPermi('system:document:edit')")
//    @Log(title = "证件信息", businessType = BusinessType.UPDATE)
    @PutMapping("/update")
    public AjaxResult edit(@RequestBody TCertificateDocument tCertificateDocument) {
        return toAjax(tCertificateDocumentService.updateTCertificateDocument(tCertificateDocument));
    }

    /**
     * 删除证件信息
     */
//    @PreAuthorize("@ss.hasPermi('system:document:remove')")
//    @Log(title = "证件信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(tCertificateDocumentService.deleteTCertificateDocumentByIds(ids));
    }

    /**
     * 导出证件信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:document:export')")
    @Log(title = "证件信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TCertificateDocument tCertificateDocument) {
        List<TCertificateDocument> list = tCertificateDocumentService.selectTCertificateDocumentList(tCertificateDocument);
        ExcelUtil<TCertificateDocument> util = new ExcelUtil<TCertificateDocument>(TCertificateDocument.class);
        util.exportExcel(response, list, "证件信息数据");
    }




}
